package com.example.scala.chapter2

import java.io.{BufferedWriter, FileOutputStream, OutputStreamWriter, PrintWriter}
import java.nio.charset.StandardCharsets
import scala.io.BufferedSource

/**
 *
 * Description:
 *
 * Create by lucienoz on 2021/10/13.
 * Copyright © 2021 lucienoz. All rights reserved.
 */
object chapter06 {
  def main(args : Array[String]) : Unit = {
//    //标准读取
//    val fooInput : String = scala.io.StdIn.readLine ( "read a line>" ) //参数为输出提示：read a line>
//    println(fooInput)
//
//    //文件读取
//    val source : BufferedSource = scala.io.Source.fromFile ( "MavenModule/data/data.txt" )
//    val strings : Iterator[String] = source.getLines ()
//    strings.foreach(println )
//
//    Console.err.println("asdasdadasd") //标准输错
//
//    println("asdasdada")

    //写文件的操作
    //调用PrintWriter类进行读写
    val printWriter = new PrintWriter( "MavenModule/data/output.txt" ,"UTF-8")
    printWriter.println("This is a PrintWriter test Text")
    printWriter.flush()
    printWriter.close()

    //使用Java IO中的
    val fileOutputStream = new FileOutputStream ( "MavenModule/data/output01.txt" ,true )
    val outputStreamWriter = new OutputStreamWriter ( fileOutputStream, StandardCharsets.UTF_8 ) //使用包装类将字节流转换成字符流
    val bufferedWriter = new BufferedWriter ( outputStreamWriter ) //包装成buffered 字符输出流
    bufferedWriter.write("This is a OutputStreamWriter test Text")
    bufferedWriter.flush()
    bufferedWriter.close()





  }

}
